﻿package  {
	import flash.geom.Point;
	public class MobObj extends GameObject {

		var VelX;
		var VelY;
		var _maxPos:Point;
		var _minPos:Point;
		var Health:int;
		var Power:int;
		var Frozen:Boolean;
		public var dead:Boolean;
		protected var _tiles:Vector.<Tile>;
		protected var _slide:Boolean;
		
		
		protected var _currentRoom:Room;
		
		
		public function MobObj(aX:Number,aY:Number,aWidth:Number,aHeight:Number) {
			super(aX,aY,aWidth,aHeight);
			_slide = false;
		}
		/*
		public function init(){
			_minPos = new Point(x,y);
			_maxPos = new Point(x + width, y + height);
			_tiles = _currentRoom.tiles2;
		}*/
		
		
		public function set tiles(t:Vector.<Tile>):void{_tiles = t}
		public function get tiles():Vector.<Tile>{return _tiles;}
		public function set currentRoom(r:Room):void{_currentRoom = r;}
		
		 public override function Update(){
			Move();
		}
		
		
		public function Move()
		{
			if(CollisionX()){
				x += VelX;
			}
			if(CollisionY()){
				y += VelY;
			}
			
		}
		
		public function TakeDamage()
		{
			
		}
		
		public function Die()
		{
			dead = true;
			if(this.parent != null)
			{
				parent.removeChild(this);
			}
		}
		
		protected function CollisionX():Boolean
		{
			
			var go:Boolean = true;
			var nextX:int;
			nextX = x;
			nextX += VelX;
							
			if(VelX > 0){
				nextX += width;
			}
			
			for(var i:int = 0; i < _tiles.length; i++){
				
					if(_tiles[i].CollisionCheck(nextX, y))
					{
						go = false;
					}
					if(_tiles[i].CollisionCheck(nextX, y + height))
					{
						go = false;
					}
				
			}
			return go;
			
		}
		
		protected function CollisionY():Boolean
		{
			var go:Boolean = true;
			var nextY:int;
			
			nextY = y;
			nextY += VelY;
				
			if(VelY > 0){
				nextY += height;
			}
			for(var i:int = 0; i < _tiles.length; i++){
				
					if(_tiles[i].CollisionCheck(x, nextY))
					{
						go = false;
					}
					if(_tiles[i].CollisionCheck(x + width, nextY))
					{
						go = false;
					}
			}
			return go;
		}
		
		
		public function Init(){
			
			
		}

	}
	
}
